/**
 * $Revision: 1.0 $
 * $Author: Eric Yang $
 * $Date: Aug 13, 2009 12:52:33 AM $
 *
 * Author: Eric Yang
 * Date  : Aug 13, 2009 12:52:33 AM
 *
 */
package com.gooex.web.action.gbuy.usercenter;

import org.c4j.string.StringTools;

import com.gooex.domain.organization.User;
import com.gooex.web.action.BaseProtectedAction;


/**
 * @author Eric Yang
 * @version 1.0
 */
public class UpdatePassword extends BaseProtectedAction {

	private String oldPassword;

	private String password;

	private String repassword;

	public String execute() throws Exception {
		if (StringTools.isBlankOrNull(oldPassword) && StringTools.isBlankOrNull(password)
				&& StringTools.isBlankOrNull(repassword)) {
			return INPUT;
		}
		if (StringTools.isBlankOrNull(password) || StringTools.isBlankOrNull(repassword)) {
			addActionError(getText("user.passsword.confirm.error"));
			return INPUT;
		}

		User user = getCurrentUser();
		if (!user.authorize(oldPassword)) {
			addActionError(getText("user.old.password.error"));
			return INPUT;
		}
		user.setPassword(password);
		try {
			userManager.saveUser(user);
		} catch (Exception e) {
			addActionError(e.getMessage());
			return INPUT;
		}
		addActionMessage(getText("user.password.update.success"));
		return SUCCESS;
	}

	public void setOldPassword(String oldPassword) {
		this.oldPassword = oldPassword;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setRepassword(String repassword) {
		this.repassword = repassword;
	}

}
